import 'package:flutter/material.dart';
import 'package:flutter_architecture/src/features/authentication/presentation/auth_screen.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Architecture',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const AuthScreen(),
    );
  }
}

// provider that returns a string value
final helloProvider = Provider<String>((ref) {
  return 'Hello World';
});

/// use: ConsumerWidget
class HelloConsumerWidget extends ConsumerWidget {
  const HelloConsumerWidget({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final hello = ref.watch(helloProvider);
    return SafeArea(child: Text(hello));
  }
}

/// use: Consumer
class HelloStatelessWidget extends StatelessWidget {
  const HelloStatelessWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Consumer(builder: (_, WidgetRef ref, __) {
      final hello = ref.watch(helloProvider);
      return SafeArea(
          child: Container(
            decoration: const BoxDecoration(color: Colors.white),
            child: Text(hello),
          ));
    });
  }
}

/// use: ConsumerStatefulWidget & ConsumerState
class HelloStatefulWidget extends ConsumerStatefulWidget {
  const HelloStatefulWidget({super.key});

  @override
  ConsumerState<ConsumerStatefulWidget> createState() =>
      _HelloStatefulWidgetState();
}

class _HelloStatefulWidgetState extends ConsumerState<HelloStatefulWidget> {
  @override
  void initState() {
    super.initState();
    final hello = ref.watch(helloProvider);
    print(hello);
  }

  @override
  Widget build(BuildContext context) {
    final hello = ref.watch(helloProvider);
    return SafeArea(child: Text(hello));
  }
}